import services
from services import BasicService
from sqlitedatastore import *


class SqliteDataStoreService(BasicService, SqliteDataStore):
    def __init__(self, debug = False):
        BasicService.__init__(self)
        SqliteDataStore.__init__(self, debug)

        #for method in filter(lambda x: not x.startswith("__"), dir(SqliteDataStore)):
        #    self.map[method] = self.__class__.__dict__[method]


    def process_command(self, command, args):
        obj = args[0]

        if command == "createschema":
            self.create_schema(obj)
            return True

        if command == "deleteschema":
            self.delete_schema(obj)
            return True

        if command == "initialize":
            SqliteDataStore.initialize(self, obj)
            return True

        if command == "save":
            SqliteDataStore.save(self, obj)
            return True

        if command == "get":
            return SqliteDataStore.get(self, obj)

        if command == "count":
            print "About to call SqliteDataStore.count"
            return SqliteDataStore.count(self, obj)

        return "null"

    def createschema(self, obj):
        return self.execute("createschema",(obj,))

    def deleteschema(self, obj):
        return self.execute("deleteschema",(obj,))

    def initialize(self, obj):
        return self.execute("initialize",(obj,))

    def save(self, obj):
        return self.execute("save",(obj,))

    def get(self, obj):
        return self.execute("get",(obj,))

    def count(self, obj):
        return self.execute("count",(obj,))

if __name__ == "__main__":
    sqlite_datastore_service = SqliteDataStoreService(True)
    services.launch_service(sqlite_datastore_service, "datastoreservice")
